import itchat

itchat.auto_login(True)

def get_count_location():
    L = []
    friend = itchat.get_friends()
    count = 0
    count1 = 0
    # 把所有找到的城市加入到队列中
    for i in friend:
        L.append(i['City'])
    s = set()
    # 用set把重复的去掉
    for i in L:
        s.add(i)
    # 遍历整个set
    for j in s:
        t = 0
        L1 = []
        str2 = ''
        for k in friend:
            # 如果找到相同城市的，把属于这个城市的昵称或备注拼保存到列表中，
            if j == k['City']:
                str1 = k['RemarkName']or k['NickName']
                L1.append(str1)
                # 统计每个城市的人数，在每一次循环的时候重置
                t += 1
        t = str(t)
        #　拼接到字符串str2中
        for i in L1:
            str2 += i+' '
        # 把结果发送给文件助手
        if j == '':
            itchat.send_msg('没有填写位置或者填写的国外地址，'+'一共有'+t+'人\n分别是:'+str2, 'filehelper')
        else:
            itchat.send_msg('位于'+j+',一共有'+t+'人\n分别是:'+str2, 'filehelper')


def get_count_sex():
    f = itchat.get_friends()
    Man =''
    Woman = ''
    manCount = 0
    womanCount = 0
    count = 0
    for i in f:
        # 遍历朋友列表，把男性姓名拼接到Man字符串中
        if i['Sex'] == 1:
            Man += (i['RemarkName'] or i['NickName']) + ' '
            manCount += 1
        # 遍历朋友列表，把女性姓名拼接到Man字符串中
        elif i['Sex'] == 2:
            Woman += (i['RemarkName'] or i['NickName']) + ' '
            womanCount += 1
        else:
            count += 1
    manCount = str(manCount)
    womanCount = str(womanCount)
    count = str(count)
    itchat.send_msg(u'男生一共'+manCount+'人，分别是'+ Man, 'filehelper')
    itchat.send_msg(u'女生一共'+womanCount+'人，分别是'+ Woman, 'filehelper')
    itchat.send_msg('未填写性别有'+count+'人')

